package pikes.ecma;

public class MemberPropertyAccess extends PrintableExpression implements IMemberExpression {

	private IMemberExpression memberExpression = null;

	private Identifier identifier = null;

	public MemberPropertyAccess(CharSequence identifier, CharSequence property) {
		this(new Identifier(identifier), property);
	}

	public MemberPropertyAccess(IMemberExpression memberExpression, CharSequence property) {
		super();
		this.memberExpression = memberExpression;
		this.identifier = new Identifier(property);
	}

	public void visit(SyntaxTreeVisitor syntaxTreeVisitor) throws EcmaSyntaxVisitingException {
		memberExpression.visit(syntaxTreeVisitor);
		syntaxTreeVisitor.dotOperator();
		identifier.visit(syntaxTreeVisitor);
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof MemberPropertyAccess)) {
			return false;
		}

		MemberPropertyAccess thatMemberPropertyAccess = (MemberPropertyAccess) obj;

		if (!(memberExpression.equals(thatMemberPropertyAccess.memberExpression))) {
			return false;
		}

		if (!(identifier.equals(thatMemberPropertyAccess.identifier))) {
			return false;
		}

		return true;
	}

	@Override
	public int hashCode() {

		int hash = 0;

		hash = hash + identifier.hashCode();

		hash = hash + memberExpression.hashCode();

		return hash;
	}
}
